<?php
namespace app\register\controller;
use think\Controller;
use think\Db;
use think\Request;

class Index extends Controller
{
    public function index()
    {
        return $this->fetch('index/register');
    }

    //接收注册信息
    public function register()
    {
        if(request()->isPost()){
            $reg = Request::instance()->post();
            var_dump($reg);
            $date = date('Y-m-d h:i:s');
            var_dump($date);
            $r_id = mt_rand(45000000,99999999);

            //将注册信息插入数据库
            Db::table('user')->insert(['username'=>$reg['username'],'pass'=>md5($reg['pass']),'addtime'=>$date,'r_id'=>$r_id]);

            //获取刚注册的用户id
            $id = Db::table('user')->getLastInsID();

            //同时为用户创建信息表新注册用户昵称默认为用户名
            Db::table('user_info')->insert(['uid'=>$id,'pname'=>$reg['username']]);
            Db::table('user_data')->insert(['uid'=>$id]);

            //创建信息公开表
            Db::table('user_publicity')->insert(['uid'=>$id]);
        }

        $this->redirect('./login/index');
    }

    //修改用户信息
    public function update()
    {
        Db::table('user')->where('id',4)->update(['pass'=>md5(123456)]);
    }
}
